package com.kotasoft.training.roogwteclipselink.client.managed.ui;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Element;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Widget;


import com.kotasoft.training.roogwteclipselink.client.scaffold.place.ProxyDetailsView;
import com.kotasoft.training.roogwteclipselink.client.managed.request.MatriculaProxy;
import com.kotasoft.training.roogwteclipselink.client.managed.request.AlumnoProxy;
import java.util.Set;
import com.kotasoft.training.roogwteclipselink.client.managed.request.AsignaturaProxy;
import com.kotasoft.training.roogwteclipselink.client.managed.ui.AsignaturaSetEditor;

/**
 * Details view for Matricula proxys.
 */
public class MatriculaMobileDetailsView extends Composite implements ProxyDetailsView<MatriculaProxy> {
	interface Binder extends UiBinder<HTMLPanel, MatriculaMobileDetailsView> {}

	private static final Binder BINDER = GWT.create(Binder.class);

	private static MatriculaMobileDetailsView instance;

	public static MatriculaMobileDetailsView instance() {
		if (instance == null) {
			instance = new MatriculaMobileDetailsView();
		}
		return instance;
	}

	MatriculaProxy proxy;
	
	@UiField Element id;
	@UiField Element version;
	@UiField Element carrera;
	@UiField Element numero;
	@UiField Element alumno;
	@UiField Element asignaturas;
	@UiField Element curso;	
	@UiField HasClickHandlers delete;

	private Delegate delegate;

	public MatriculaMobileDetailsView() {
		initWidget(BINDER.createAndBindUi(this));
	}

  	public Widget asWidget() {
		return this;
	}
  
	public boolean confirm(String msg) {
		return Window.confirm(msg);
	}

	public MatriculaProxy getValue() {
		return proxy;
	}

	@UiHandler("delete")
	public void onDeleteClicked(ClickEvent e) {
		delegate.deleteClicked();
	}

	public void setDelegate(Delegate delegate) {
		this.delegate = delegate;
	}

	public void setValue(MatriculaProxy proxy) {
		this.proxy = proxy;
		id.setInnerText(proxy.getId() == null ? "" : String.valueOf(proxy.getId()));
		version.setInnerText(proxy.getVersion() == null ? "" : String.valueOf(proxy.getVersion()));
		carrera.setInnerText(proxy.getCarrera() == null ? "" : String.valueOf(proxy.getCarrera()));
		numero.setInnerText(proxy.getNumero() == null ? "" : String.valueOf(proxy.getNumero()));
		alumno.setInnerText(proxy.getAlumno() == null ? "" : com.kotasoft.training.roogwteclipselink.client.managed.ui.AlumnoProxyRenderer.instance().render(proxy.getAlumno()));
		asignaturas.setInnerText(proxy.getAsignaturas() == null ? "" : com.kotasoft.training.roogwteclipselink.client.scaffold.place.CollectionRenderer.of(com.kotasoft.training.roogwteclipselink.client.managed.ui.AsignaturaProxyRenderer.instance()).render(proxy.getAsignaturas()));
		curso.setInnerText(proxy.getCurso() == null ? "" : String.valueOf(proxy.getCurso()));
	}
}
